package DAO;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import DTO.DTO_Area;
import DTO.DTO_Barra;
import DTO.DTO_Cafeteria;
import DTO.DTO_Cocina;
import Entities.Entity_Area;
import Entities.Entity_Barra;
import Entities.Entity_Cafeteria;
import Hibernate.HibernateUtil;

public class DAO_Area {
		
		private static DAO_Area instancia = null;
		private static SessionFactory sf = null;

		public static DAO_Area getInstancia(){
			if(instancia == null){
				sf = HibernateUtil.getSessionFactory();
				instancia = new DAO_Area();
			} 
			return instancia;
		}
		
		public List<DTO_Area> getAreas(){
			Session session = sf.openSession();
			String consulta = "select a from Entity_Area a";
			Query q = session.createQuery(consulta);
			List<Entity_Area> areas = q.list();
			List<DTO_Area> areasDTO = new ArrayList<DTO_Area>();
			for(Entity_Area a: areas)
				if(a instanceof Entity_Barra){
					DTO_Barra b = new DTO_Barra();
					areasDTO.add(b);
				}
				else if(a instanceof Entity_Cafeteria){
					DTO_Cafeteria c = new DTO_Cafeteria();
					areasDTO.add(c);
				}
				else{
					DTO_Cocina co = new DTO_Cocina();
					areasDTO.add(co);
				}
						
			return areasDTO;
		}
		

		
	
}
